#include<iostream>
using namespace std;
const int MAXN = 10000;
int n, high[MAXN];
//389 207 155 300 299 170 158 65
//int LIS()
//{
//	int ans = 1;
//	int dp[MAXN] = { 0 };
//	dp[1] = 1;
//	for (int i = 2; i <= n; i++) {
//		int max = 0;
//		for (int j = 0; j < i; j++) {
//			if (dp[j] > max && high[i] > high[j])
//				max = dp[j];
//			dp[i] = max + 1;
//			if (dp[i] > ans)ans = dp[i];
//		}
//	}
//	return ans;
//}

int LIS()
{
	int len = 1;
	int d[MAXN] = { 0 };
	d[1] = high[1];
	for (int i = 2; i <= n; i++) {
		if (high[i] > d[len]) d[++len] = high[i];
		else {
			int j = lower_bound(d + 1, d + len + 1, high[i]) - d;
			d[j] = high[i];
		}
	}
	return len;
}

int main()
{
	while (cin >> n) {
		for (int i = 1; i <= n; i++)
			cin >> high[i];
		cout << LIS() << endl;
	}
	return 0;
}